package com.haixiaoke.saas.workOrder.state.server;

import com.haixiaoke.saas.common.constant.WorkOrderConstants;
import com.haixiaoke.saas.workOrder.domain.WorkOrderPerson;
import com.haixiaoke.saas.workOrder.domain.WorkOrder;
import com.haixiaoke.saas.workOrder.domain.WorkOrderRecord;
import com.haixiaoke.saas.workOrder.state.role.CleaningWorkOrderTypeServerRole;
import com.haixiaoke.saas.workOrder.state.role.IntermediaryWorkOrderTypeServerRole;
import com.haixiaoke.saas.workOrder.state.role.MaintenanceWorkOrderTypeServerRole;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author panda
 * @Date 2024/9/3
 **/
public class WorkOrderTypeServerRole implements IWorkOrderTypeServerRole {

    private static final Logger LOG = LoggerFactory.getLogger(WorkOrderTypeServerRole.class);

    private final Map<String, ISpecificWorkOrderTypeServerRole> specificWorkOrderTypeServerRoleMap = new HashMap<>();
    private final WorkOrder workOrder;

    public WorkOrderTypeServerRole(WorkOrder workOrder) {
        LOG.info("状态服务方：WorkOrderTypeServerRole，初始化特定状态服务方对象");
        this.workOrder = workOrder;
        specificWorkOrderTypeServerRoleMap.put(WorkOrderConstants.WORK_ORDER_TYPE_MAINTENANCE, new MaintenanceWorkOrderTypeServerRole(this));
        specificWorkOrderTypeServerRoleMap.put(WorkOrderConstants.WORK_ORDER_TYPE_CLEANING, new CleaningWorkOrderTypeServerRole(this));
        specificWorkOrderTypeServerRoleMap.put(WorkOrderConstants.WORK_ORDER_TYPE_INTERMEDIARY, new IntermediaryWorkOrderTypeServerRole(this));

    }

    private ISpecificWorkOrderTypeServerRole getSpecificWorkOrderTypeServerRole() {
        //获取特定工单类型服务方对象
        return specificWorkOrderTypeServerRoleMap.get(workOrder.getWorkOrderType());
    }

    @Override
    public int insertWorkOrder(String phone) {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.insertWorkOrder(workOrder, phone);
    }

    @Override
    public int rejectWorkOrder(WorkOrderRecord workOrderRecord, String userName, String flatUserName) {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.rejectWorkOrder(workOrder, workOrderRecord, userName, flatUserName);
    }

    @Override
    public int dispatchWorkOrder(WorkOrderPerson workOrderPerson) {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.dispatchWorkOrder(workOrder, workOrderPerson);
    }

    @Override
    public int receivedWorkOrder(WorkOrderRecord workOrderRecord, Long busUserId, String maintenanceTenantId) {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.receivedWorkOrder(workOrder, workOrderRecord, busUserId, maintenanceTenantId);
    }

    @Override
    public int paymentCompletion(WorkOrderRecord record) {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.paymentCompletion(workOrder, record);
    }

    @Override
    public int requestRejectionWorkOrder(WorkOrderRecord workOrderRecord, Long busUserId, String maintenanceTenantId) {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.requestRejectionWorkOrder(workOrder, workOrderRecord, busUserId, maintenanceTenantId);
    }

    @Override
    public int auditDenialWorkOrder(WorkOrderRecord workOrderRecord, String username) {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.auditDenialWorkOrder(workOrder, workOrderRecord, username);
    }

    @Override
    public int beingRepaired() {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.beingRepaired(workOrder);
    }

    @Override
    public int submitPaymentSlip() {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.submitPaymentSlip(workOrder);
    }

    @Override
    public int revocationRejectionWorkOrder(WorkOrderRecord workOrderRecord, Long busUserId, String maintenanceTenantId) {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.revocationRejectionWorkOrder(workOrder, workOrderRecord, busUserId, maintenanceTenantId);
    }

    @Override
    public void applyTemporaryPassword(String name,String phone,Long busUserId) {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        specificWorkOrderTypeServerRole.applyTemporaryPassword(workOrder,name,phone, busUserId);
    }

    @Override
    public int updateWorkOrder(String phone) {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.updateWorkOrder(workOrder, phone);
    }

    @Override
    public int confirmLookHouse(Long userId, String tenantId) {
        ISpecificWorkOrderTypeServerRole specificWorkOrderTypeServerRole = getSpecificWorkOrderTypeServerRole();
        return specificWorkOrderTypeServerRole.confirmLookHouse(workOrder, userId, tenantId);
    }
}
